{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import h2o\n",
    "from h2o.estimators.gbm import H2OGradientBoostingEstimator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"overflow:auto\"><table style=\"width:50%\"><tr><td>H2O cluster uptime: </td>\n",
       "<td>5 seconds 730 milliseconds </td></tr>\n",
       "<tr><td>H2O cluster version: </td>\n",
       "<td>3.7.0.99999</td></tr>\n",
       "<tr><td>H2O cluster name: </td>\n",
       "<td>spIdea</td></tr>\n",
       "<tr><td>H2O cluster total nodes: </td>\n",
       "<td>1</td></tr>\n",
       "<tr><td>H2O cluster total free memory: </td>\n",
       "<td>12.44 GB</td></tr>\n",
       "<tr><td>H2O cluster total cores: </td>\n",
       "<td>8</td></tr>\n",
       "<tr><td>H2O cluster allowed cores: </td>\n",
       "<td>8</td></tr>\n",
       "<tr><td>H2O cluster healthy: </td>\n",
       "<td>True</td></tr>\n",
       "<tr><td>H2O Connection ip: </td>\n",
       "<td>127.0.0.1</td></tr>\n",
       "<tr><td>H2O Connection port: </td>\n",
       "<td>54321</td></tr>\n",
       "<tr><td>H2O Connection proxy: </td>\n",
       "<td>None</td></tr>\n",
       "<tr><td>Python Version: </td>\n",
       "<td>3.5.0</td></tr></table></div>"
      ],
      "text/plain": [
       "------------------------------  --------------------------\n",
       "H2O cluster uptime:             5 seconds 730 milliseconds\n",
       "H2O cluster version:            3.7.0.99999\n",
       "H2O cluster name:               spIdea\n",
       "H2O cluster total nodes:        1\n",
       "H2O cluster total free memory:  12.44 GB\n",
       "H2O cluster total cores:        8\n",
       "H2O cluster allowed cores:      8\n",
       "H2O cluster healthy:            True\n",
       "H2O Connection ip:              127.0.0.1\n",
       "H2O Connection port:            54321\n",
       "H2O Connection proxy:\n",
       "Python Version:                 3.5.0\n",
       "------------------------------  --------------------------"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Connect to a pre-existing cluster\n",
    "h2o.init()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Parse Progress: [##################################################] 100%\n"
     ]
    }
   ],
   "source": [
    "from h2o.utils.shared_utils import _locate # private function. used to find files within h2o git project directory.\n",
    "\n",
    "df = h2o.import_file(path=_locate(\"smalldata/logreg/prostate.csv\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Rows:380 Cols:9\n",
      "\n",
      "Chunk compression summary: \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div style=\"overflow:auto\"><table style=\"width:50%\"><tr><td><b>chunk_type</b></td>\n",
       "<td><b>chunk_name</b></td>\n",
       "<td><b>count</b></td>\n",
       "<td><b>count_percentage</b></td>\n",
       "<td><b>size</b></td>\n",
       "<td><b>size_percentage</b></td></tr>\n",
       "<tr><td>CBS</td>\n",
       "<td>Bits</td>\n",
       "<td>1</td>\n",
       "<td>11.111112</td>\n",
       "<td>    118  B</td>\n",
       "<td>2.4210093</td></tr>\n",
       "<tr><td>C1N</td>\n",
       "<td>1-Byte Integers (w/o NAs)</td>\n",
       "<td>5</td>\n",
       "<td>55.555557</td>\n",
       "<td>    2.2 KB</td>\n",
       "<td>45.958145</td></tr>\n",
       "<tr><td>C2</td>\n",
       "<td>2-Byte Integers</td>\n",
       "<td>1</td>\n",
       "<td>11.111112</td>\n",
       "<td>    828  B</td>\n",
       "<td>16.9881</td></tr>\n",
       "<tr><td>C2S</td>\n",
       "<td>2-Byte Fractions</td>\n",
       "<td>2</td>\n",
       "<td>22.222223</td>\n",
       "<td>    1.6 KB</td>\n",
       "<td>34.632744</td></tr></table></div>"
      ],
      "text/plain": [
       "chunk_type    chunk_name                 count    count_percentage    size    size_percentage\n",
       "------------  -------------------------  -------  ------------------  ------  -----------------\n",
       "CBS           Bits                       1        11.1111             118  B  2.42101\n",
       "C1N           1-Byte Integers (w/o NAs)  5        55.5556             2.2 KB  45.9581\n",
       "C2            2-Byte Integers            1        11.1111             828  B  16.9881\n",
       "C2S           2-Byte Fractions           2        22.2222             1.6 KB  34.6327"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Frame distribution summary: \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div style=\"overflow:auto\"><table style=\"width:50%\"><tr><td><b></b></td>\n",
       "<td><b>size</b></td>\n",
       "<td><b>number_of_rows</b></td>\n",
       "<td><b>number_of_chunks_per_column</b></td>\n",
       "<td><b>number_of_chunks</b></td></tr>\n",
       "<tr><td>172.16.2.84:54321</td>\n",
       "<td>    4.8 KB</td>\n",
       "<td>380.0</td>\n",
       "<td>1.0</td>\n",
       "<td>9.0</td></tr>\n",
       "<tr><td>mean</td>\n",
       "<td>    4.8 KB</td>\n",
       "<td>380.0</td>\n",
       "<td>1.0</td>\n",
       "<td>9.0</td></tr>\n",
       "<tr><td>min</td>\n",
       "<td>    4.8 KB</td>\n",
       "<td>380.0</td>\n",
       "<td>1.0</td>\n",
       "<td>9.0</td></tr>\n",
       "<tr><td>max</td>\n",
       "<td>    4.8 KB</td>\n",
       "<td>380.0</td>\n",
       "<td>1.0</td>\n",
       "<td>9.0</td></tr>\n",
       "<tr><td>stddev</td>\n",
       "<td>      0  B</td>\n",
       "<td>0.0</td>\n",
       "<td>0.0</td>\n",
       "<td>0.0</td></tr>\n",
       "<tr><td>total</td>\n",
       "<td>    4.8 KB</td>\n",
       "<td>380.0</td>\n",
       "<td>1.0</td>\n",
       "<td>9.0</td></tr></table></div>"
      ],
      "text/plain": [
       "                   size    number_of_rows    number_of_chunks_per_column    number_of_chunks\n",
       "-----------------  ------  ----------------  -----------------------------  ------------------\n",
       "172.16.2.84:54321  4.8 KB  380               1                              9\n",
       "mean               4.8 KB  380               1                              9\n",
       "min                4.8 KB  380               1                              9\n",
       "max                4.8 KB  380               1                              9\n",
       "stddev             0  B    0                 0                              0\n",
       "total              4.8 KB  380               1                              9"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<tr><th>       </th><th>ID                </th><th>CAPSULE           </th><th>AGE              </th><th>RACE              </th><th>DPROS             </th><th>DCAPS             </th><th>PSA               </th><th>VOL               </th><th>GLEASON           </th></tr>\n",
       "<tr><td>type   </td><td>int               </td><td>int               </td><td>int              </td><td>int               </td><td>int               </td><td>int               </td><td>real              </td><td>real              </td><td>int               </td></tr>\n",
       "<tr><td>mins   </td><td>1.0               </td><td>0.0               </td><td>43.0             </td><td>0.0               </td><td>1.0               </td><td>1.0               </td><td>0.3               </td><td>0.0               </td><td>0.0               </td></tr>\n",
       "<tr><td>mean   </td><td>190.5             </td><td>0.4026315789473684</td><td>66.03947368421049</td><td>1.0868421052631572</td><td>2.2710526315789488</td><td>1.1078947368421048</td><td>15.408631578947375</td><td>15.812921052631573</td><td>6.3842105263157904</td></tr>\n",
       "<tr><td>maxs   </td><td>380.0             </td><td>1.0               </td><td>79.0             </td><td>2.0               </td><td>4.0               </td><td>2.0               </td><td>139.70000000000002</td><td>97.60000000000001 </td><td>9.0               </td></tr>\n",
       "<tr><td>sigma  </td><td>109.84079387914127</td><td>0.4910743389630552</td><td>6.527071269173311</td><td>0.3087732580252793</td><td>1.0001076181502861</td><td>0.3106564493514939</td><td>19.99757266856046 </td><td>18.347619967271175</td><td>1.0919533744261092</td></tr>\n",
       "<tr><td>zeros  </td><td>0                 </td><td>227               </td><td>0                </td><td>3                 </td><td>0                 </td><td>0                 </td><td>0                 </td><td>167               </td><td>2                 </td></tr>\n",
       "<tr><td>missing</td><td>0                 </td><td>0                 </td><td>0                </td><td>0                 </td><td>0                 </td><td>0                 </td><td>0                 </td><td>0                 </td><td>0                 </td></tr>\n",
       "<tr><td>0      </td><td>1.0               </td><td>0.0               </td><td>65.0             </td><td>1.0               </td><td>2.0               </td><td>1.0               </td><td>1.4000000000000001</td><td>0.0               </td><td>6.0               </td></tr>\n",
       "<tr><td>1      </td><td>2.0               </td><td>0.0               </td><td>72.0             </td><td>1.0               </td><td>3.0               </td><td>2.0               </td><td>6.7               </td><td>0.0               </td><td>7.0               </td></tr>\n",
       "<tr><td>2      </td><td>3.0               </td><td>0.0               </td><td>70.0             </td><td>1.0               </td><td>1.0               </td><td>2.0               </td><td>4.9               </td><td>0.0               </td><td>6.0               </td></tr>\n",
       "<tr><td>3      </td><td>4.0               </td><td>0.0               </td><td>76.0             </td><td>2.0               </td><td>2.0               </td><td>1.0               </td><td>51.2              </td><td>20.0              </td><td>7.0               </td></tr>\n",
       "<tr><td>4      </td><td>5.0               </td><td>0.0               </td><td>69.0             </td><td>1.0               </td><td>1.0               </td><td>1.0               </td><td>12.3              </td><td>55.9              </td><td>6.0               </td></tr>\n",
       "<tr><td>5      </td><td>6.0               </td><td>1.0               </td><td>71.0             </td><td>1.0               </td><td>3.0               </td><td>2.0               </td><td>3.3000000000000003</td><td>0.0               </td><td>8.0               </td></tr>\n",
       "<tr><td>6      </td><td>7.0               </td><td>0.0               </td><td>68.0             </td><td>2.0               </td><td>4.0               </td><td>2.0               </td><td>31.900000000000002</td><td>0.0               </td><td>7.0               </td></tr>\n",
       "<tr><td>7      </td><td>8.0               </td><td>0.0               </td><td>61.0             </td><td>2.0               </td><td>4.0               </td><td>2.0               </td><td>66.7              </td><td>27.2              </td><td>7.0               </td></tr>\n",
       "<tr><td>8      </td><td>9.0               </td><td>0.0               </td><td>69.0             </td><td>1.0               </td><td>1.0               </td><td>1.0               </td><td>3.9               </td><td>24.0              </td><td>7.0               </td></tr>\n",
       "<tr><td>9      </td><td>10.0              </td><td>0.0               </td><td>68.0             </td><td>2.0               </td><td>1.0               </td><td>2.0               </td><td>13.0              </td><td>0.0               </td><td>6.0               </td></tr>\n",
       "</table>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Remove ID from training frame\n",
    "train = df.drop(\"ID\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# For VOL & GLEASON, a zero really means \"missing\"\n",
    "vol = train['VOL']\n",
    "vol[vol == 0] = None\n",
    "gle = train['GLEASON']\n",
    "gle[gle == 0] = None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Convert CAPSULE to a logical factor\n",
    "train['CAPSULE'] = train['CAPSULE'].asfactor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Rows:380 Cols:8\n",
      "\n",
      "Chunk compression summary: \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div style=\"overflow:auto\"><table style=\"width:50%\"><tr><td><b>chunk_type</b></td>\n",
       "<td><b>chunk_name</b></td>\n",
       "<td><b>count</b></td>\n",
       "<td><b>count_percentage</b></td>\n",
       "<td><b>size</b></td>\n",
       "<td><b>size_percentage</b></td></tr>\n",
       "<tr><td>CBS</td>\n",
       "<td>Bits</td>\n",
       "<td>1</td>\n",
       "<td>12.5</td>\n",
       "<td>    118  B</td>\n",
       "<td>2.9164608</td></tr>\n",
       "<tr><td>C1N</td>\n",
       "<td>1-Byte Integers (w/o NAs)</td>\n",
       "<td>5</td>\n",
       "<td>62.5</td>\n",
       "<td>    2.2 KB</td>\n",
       "<td>55.363323</td></tr>\n",
       "<tr><td>C2S</td>\n",
       "<td>2-Byte Fractions</td>\n",
       "<td>2</td>\n",
       "<td>25.0</td>\n",
       "<td>    1.6 KB</td>\n",
       "<td>41.72022</td></tr></table></div>"
      ],
      "text/plain": [
       "chunk_type    chunk_name                 count    count_percentage    size    size_percentage\n",
       "------------  -------------------------  -------  ------------------  ------  -----------------\n",
       "CBS           Bits                       1        12.5                118  B  2.91646\n",
       "C1N           1-Byte Integers (w/o NAs)  5        62.5                2.2 KB  55.3633\n",
       "C2S           2-Byte Fractions           2        25                  1.6 KB  41.7202"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Frame distribution summary: \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div style=\"overflow:auto\"><table style=\"width:50%\"><tr><td><b></b></td>\n",
       "<td><b>size</b></td>\n",
       "<td><b>number_of_rows</b></td>\n",
       "<td><b>number_of_chunks_per_column</b></td>\n",
       "<td><b>number_of_chunks</b></td></tr>\n",
       "<tr><td>172.16.2.84:54321</td>\n",
       "<td>    4.0 KB</td>\n",
       "<td>380.0</td>\n",
       "<td>1.0</td>\n",
       "<td>8.0</td></tr>\n",
       "<tr><td>mean</td>\n",
       "<td>    4.0 KB</td>\n",
       "<td>380.0</td>\n",
       "<td>1.0</td>\n",
       "<td>8.0</td></tr>\n",
       "<tr><td>min</td>\n",
       "<td>    4.0 KB</td>\n",
       "<td>380.0</td>\n",
       "<td>1.0</td>\n",
       "<td>8.0</td></tr>\n",
       "<tr><td>max</td>\n",
       "<td>    4.0 KB</td>\n",
       "<td>380.0</td>\n",
       "<td>1.0</td>\n",
       "<td>8.0</td></tr>\n",
       "<tr><td>stddev</td>\n",
       "<td>      0  B</td>\n",
       "<td>0.0</td>\n",
       "<td>0.0</td>\n",
       "<td>0.0</td></tr>\n",
       "<tr><td>total</td>\n",
       "<td>    4.0 KB</td>\n",
       "<td>380.0</td>\n",
       "<td>1.0</td>\n",
       "<td>8.0</td></tr></table></div>"
      ],
      "text/plain": [
       "                   size    number_of_rows    number_of_chunks_per_column    number_of_chunks\n",
       "-----------------  ------  ----------------  -----------------------------  ------------------\n",
       "172.16.2.84:54321  4.0 KB  380               1                              8\n",
       "mean               4.0 KB  380               1                              8\n",
       "min                4.0 KB  380               1                              8\n",
       "max                4.0 KB  380               1                              8\n",
       "stddev             0  B    0                 0                              0\n",
       "total              4.0 KB  380               1                              8"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<tr><th>       </th><th>CAPSULE           </th><th>AGE              </th><th>RACE              </th><th>DPROS             </th><th>DCAPS             </th><th>PSA               </th><th>VOL               </th><th>GLEASON           </th></tr>\n",
       "<tr><td>type   </td><td>enum              </td><td>int              </td><td>int               </td><td>int               </td><td>int               </td><td>real              </td><td>real              </td><td>int               </td></tr>\n",
       "<tr><td>mins   </td><td>0.0               </td><td>43.0             </td><td>0.0               </td><td>1.0               </td><td>1.0               </td><td>0.3               </td><td>0.0               </td><td>0.0               </td></tr>\n",
       "<tr><td>mean   </td><td>0.4026315789473684</td><td>66.03947368421049</td><td>1.0868421052631572</td><td>2.2710526315789488</td><td>1.1078947368421048</td><td>15.408631578947375</td><td>15.812921052631573</td><td>6.3842105263157904</td></tr>\n",
       "<tr><td>maxs   </td><td>1.0               </td><td>79.0             </td><td>2.0               </td><td>4.0               </td><td>2.0               </td><td>139.70000000000002</td><td>97.60000000000001 </td><td>9.0               </td></tr>\n",
       "<tr><td>sigma  </td><td>0.4910743389630552</td><td>6.527071269173311</td><td>0.3087732580252793</td><td>1.0001076181502861</td><td>0.3106564493514939</td><td>19.99757266856046 </td><td>18.347619967271175</td><td>1.0919533744261092</td></tr>\n",
       "<tr><td>zeros  </td><td>227               </td><td>0                </td><td>3                 </td><td>0                 </td><td>0                 </td><td>0                 </td><td>167               </td><td>2                 </td></tr>\n",
       "<tr><td>missing</td><td>0                 </td><td>0                </td><td>0                 </td><td>0                 </td><td>0                 </td><td>0                 </td><td>0                 </td><td>0                 </td></tr>\n",
       "<tr><td>0      </td><td>0                 </td><td>65.0             </td><td>1.0               </td><td>2.0               </td><td>1.0               </td><td>1.4000000000000001</td><td>0.0               </td><td>6.0               </td></tr>\n",
       "<tr><td>1      </td><td>0                 </td><td>72.0             </td><td>1.0               </td><td>3.0               </td><td>2.0               </td><td>6.7               </td><td>0.0               </td><td>7.0               </td></tr>\n",
       "<tr><td>2      </td><td>0                 </td><td>70.0             </td><td>1.0               </td><td>1.0               </td><td>2.0               </td><td>4.9               </td><td>0.0               </td><td>6.0               </td></tr>\n",
       "<tr><td>3      </td><td>0                 </td><td>76.0             </td><td>2.0               </td><td>2.0               </td><td>1.0               </td><td>51.2              </td><td>20.0              </td><td>7.0               </td></tr>\n",
       "<tr><td>4      </td><td>0                 </td><td>69.0             </td><td>1.0               </td><td>1.0               </td><td>1.0               </td><td>12.3              </td><td>55.9              </td><td>6.0               </td></tr>\n",
       "<tr><td>5      </td><td>1                 </td><td>71.0             </td><td>1.0               </td><td>3.0               </td><td>2.0               </td><td>3.3000000000000003</td><td>0.0               </td><td>8.0               </td></tr>\n",
       "<tr><td>6      </td><td>0                 </td><td>68.0             </td><td>2.0               </td><td>4.0               </td><td>2.0               </td><td>31.900000000000002</td><td>0.0               </td><td>7.0               </td></tr>\n",
       "<tr><td>7      </td><td>0                 </td><td>61.0             </td><td>2.0               </td><td>4.0               </td><td>2.0               </td><td>66.7              </td><td>27.2              </td><td>7.0               </td></tr>\n",
       "<tr><td>8      </td><td>0                 </td><td>69.0             </td><td>1.0               </td><td>1.0               </td><td>1.0               </td><td>3.9               </td><td>24.0              </td><td>7.0               </td></tr>\n",
       "<tr><td>9      </td><td>0                 </td><td>68.0             </td><td>2.0               </td><td>1.0               </td><td>2.0               </td><td>13.0              </td><td>0.0               </td><td>6.0               </td></tr>\n",
       "</table>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# See that the data is ready\n",
    "train.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "gbm Model Build Progress: [##################################################] 100%\n"
     ]
    }
   ],
   "source": [
    "# Run GBM\n",
    "my_gbm = H2OGradientBoostingEstimator(distribution = \"bernoulli\", ntrees=50, learn_rate=0.1)\n",
    "\n",
    "my_gbm.train(x=list(range(1,train.ncol)), y=\"CAPSULE\", training_frame=train, validation_frame=train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "ModelMetricsBinomial: gbm\n",
      "** Reported on test data. **\n",
      "\n",
      "MSE: 0.07584147467507414\n",
      "R^2: 0.6846762562816877\n",
      "LogLoss: 0.2744668128481441\n",
      "AUC: 0.9780311537243385\n",
      "Gini: 0.9560623074486769\n",
      "\n",
      "Confusion Matrix (Act/Pred) for max f1 @ threshold = 0.4549496668047897: \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div style=\"overflow:auto\"><table style=\"width:50%\"><tr><td><b></b></td>\n",
       "<td><b>0</b></td>\n",
       "<td><b>1</b></td>\n",
       "<td><b>Error</b></td>\n",
       "<td><b>Rate</b></td></tr>\n",
       "<tr><td>0</td>\n",
       "<td>216.0</td>\n",
       "<td>11.0</td>\n",
       "<td>0.0485</td>\n",
       "<td> (11.0/227.0)</td></tr>\n",
       "<tr><td>1</td>\n",
       "<td>14.0</td>\n",
       "<td>139.0</td>\n",
       "<td>0.0915</td>\n",
       "<td> (14.0/153.0)</td></tr>\n",
       "<tr><td>Total</td>\n",
       "<td>230.0</td>\n",
       "<td>150.0</td>\n",
       "<td>0.0658</td>\n",
       "<td> (25.0/380.0)</td></tr></table></div>"
      ],
      "text/plain": [
       "       0    1    Error    Rate\n",
       "-----  ---  ---  -------  ------------\n",
       "0      216  11   0.0485   (11.0/227.0)\n",
       "1      14   139  0.0915   (14.0/153.0)\n",
       "Total  230  150  0.0658   (25.0/380.0)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Maximum Metrics: Maximum metrics at their respective thresholds\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div style=\"overflow:auto\"><table style=\"width:50%\"><tr><td><b>metric</b></td>\n",
       "<td><b>threshold</b></td>\n",
       "<td><b>value</b></td>\n",
       "<td><b>idx</b></td></tr>\n",
       "<tr><td>max f1</td>\n",
       "<td>0.4549497</td>\n",
       "<td>0.9174917</td>\n",
       "<td>149.0</td></tr>\n",
       "<tr><td>max f2</td>\n",
       "<td>0.3032010</td>\n",
       "<td>0.9394314</td>\n",
       "<td>196.0</td></tr>\n",
       "<tr><td>max f0point5</td>\n",
       "<td>0.4728313</td>\n",
       "<td>0.9244265</td>\n",
       "<td>146.0</td></tr>\n",
       "<tr><td>max accuracy</td>\n",
       "<td>0.4549497</td>\n",
       "<td>0.9342105</td>\n",
       "<td>149.0</td></tr>\n",
       "<tr><td>max precision</td>\n",
       "<td>0.9747938</td>\n",
       "<td>1.0</td>\n",
       "<td>0.0</td></tr>\n",
       "<tr><td>max absolute_MCC</td>\n",
       "<td>0.4549497</td>\n",
       "<td>0.8629130</td>\n",
       "<td>149.0</td></tr>\n",
       "<tr><td>max min_per_class_accuracy</td>\n",
       "<td>0.4373995</td>\n",
       "<td>0.9215686</td>\n",
       "<td>156.0</td></tr></table></div>"
      ],
      "text/plain": [
       "metric                      threshold    value     idx\n",
       "--------------------------  -----------  --------  -----\n",
       "max f1                      0.45495      0.917492  149\n",
       "max f2                      0.303201     0.939431  196\n",
       "max f0point5                0.472831     0.924426  146\n",
       "max accuracy                0.45495      0.934211  149\n",
       "max precision               0.974794     1         0\n",
       "max absolute_MCC            0.45495      0.862913  149\n",
       "max min_per_class_accuracy  0.437399     0.921569  156"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Gains/Lift Table: Avg response rate: 40.26 %\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div style=\"overflow:auto\"><table style=\"width:50%\"><tr><td><b></b></td>\n",
       "<td><b>group</b></td>\n",
       "<td><b>lower_threshold</b></td>\n",
       "<td><b>cumulative_data_fraction</b></td>\n",
       "<td><b>response_rate</b></td>\n",
       "<td><b>cumulative_response_rate</b></td>\n",
       "<td><b>capture_rate</b></td>\n",
       "<td><b>cumulative_capture_rate</b></td>\n",
       "<td><b>lift</b></td>\n",
       "<td><b>cumulative_lift</b></td>\n",
       "<td><b>gain</b></td>\n",
       "<td><b>cumulative_gain</b></td></tr>\n",
       "<tr><td></td>\n",
       "<td>1</td>\n",
       "<td>0.9405750</td>\n",
       "<td>0.05</td>\n",
       "<td>1.0</td>\n",
       "<td>1.0</td>\n",
       "<td>0.1241830</td>\n",
       "<td>0.1241830</td>\n",
       "<td>2.4836601</td>\n",
       "<td>2.4836601</td>\n",
       "<td>148.3660131</td>\n",
       "<td>148.3660131</td></tr>\n",
       "<tr><td></td>\n",
       "<td>2</td>\n",
       "<td>0.8921980</td>\n",
       "<td>0.1</td>\n",
       "<td>1.0</td>\n",
       "<td>1.0</td>\n",
       "<td>0.1241830</td>\n",
       "<td>0.2483660</td>\n",
       "<td>2.4836601</td>\n",
       "<td>2.4836601</td>\n",
       "<td>148.3660131</td>\n",
       "<td>148.3660131</td></tr>\n",
       "<tr><td></td>\n",
       "<td>3</td>\n",
       "<td>0.8263695</td>\n",
       "<td>0.15</td>\n",
       "<td>1.0</td>\n",
       "<td>1.0</td>\n",
       "<td>0.1241830</td>\n",
       "<td>0.3725490</td>\n",
       "<td>2.4836601</td>\n",
       "<td>2.4836601</td>\n",
       "<td>148.3660131</td>\n",
       "<td>148.3660131</td></tr>\n",
       "<tr><td></td>\n",
       "<td>4</td>\n",
       "<td>0.7595460</td>\n",
       "<td>0.2</td>\n",
       "<td>0.9473684</td>\n",
       "<td>0.9868421</td>\n",
       "<td>0.1176471</td>\n",
       "<td>0.4901961</td>\n",
       "<td>2.3529412</td>\n",
       "<td>2.4509804</td>\n",
       "<td>135.2941176</td>\n",
       "<td>145.0980392</td></tr>\n",
       "<tr><td></td>\n",
       "<td>5</td>\n",
       "<td>0.7081926</td>\n",
       "<td>0.25</td>\n",
       "<td>1.0</td>\n",
       "<td>0.9894737</td>\n",
       "<td>0.1241830</td>\n",
       "<td>0.6143791</td>\n",
       "<td>2.4836601</td>\n",
       "<td>2.4575163</td>\n",
       "<td>148.3660131</td>\n",
       "<td>145.7516340</td></tr>\n",
       "<tr><td></td>\n",
       "<td>6</td>\n",
       "<td>0.6364312</td>\n",
       "<td>0.3</td>\n",
       "<td>0.8947368</td>\n",
       "<td>0.9736842</td>\n",
       "<td>0.1111111</td>\n",
       "<td>0.7254902</td>\n",
       "<td>2.2222222</td>\n",
       "<td>2.4183007</td>\n",
       "<td>122.2222222</td>\n",
       "<td>141.8300654</td></tr>\n",
       "<tr><td></td>\n",
       "<td>7</td>\n",
       "<td>0.5478651</td>\n",
       "<td>0.35</td>\n",
       "<td>0.6842105</td>\n",
       "<td>0.9323308</td>\n",
       "<td>0.0849673</td>\n",
       "<td>0.8104575</td>\n",
       "<td>1.6993464</td>\n",
       "<td>2.3155929</td>\n",
       "<td>69.9346405</td>\n",
       "<td>131.5592904</td></tr>\n",
       "<tr><td></td>\n",
       "<td>8</td>\n",
       "<td>0.4499827</td>\n",
       "<td>0.4</td>\n",
       "<td>0.7894737</td>\n",
       "<td>0.9144737</td>\n",
       "<td>0.0980392</td>\n",
       "<td>0.9084967</td>\n",
       "<td>1.9607843</td>\n",
       "<td>2.2712418</td>\n",
       "<td>96.0784314</td>\n",
       "<td>127.1241830</td></tr>\n",
       "<tr><td></td>\n",
       "<td>9</td>\n",
       "<td>0.3927870</td>\n",
       "<td>0.45</td>\n",
       "<td>0.2105263</td>\n",
       "<td>0.8362573</td>\n",
       "<td>0.0261438</td>\n",
       "<td>0.9346405</td>\n",
       "<td>0.5228758</td>\n",
       "<td>2.0769789</td>\n",
       "<td>-47.7124183</td>\n",
       "<td>107.6978940</td></tr>\n",
       "<tr><td></td>\n",
       "<td>10</td>\n",
       "<td>0.3207657</td>\n",
       "<td>0.5</td>\n",
       "<td>0.3157895</td>\n",
       "<td>0.7842105</td>\n",
       "<td>0.0392157</td>\n",
       "<td>0.9738562</td>\n",
       "<td>0.7843137</td>\n",
       "<td>1.9477124</td>\n",
       "<td>-21.5686275</td>\n",
       "<td>94.7712418</td></tr>\n",
       "<tr><td></td>\n",
       "<td>11</td>\n",
       "<td>0.2425744</td>\n",
       "<td>0.55</td>\n",
       "<td>0.1578947</td>\n",
       "<td>0.7272727</td>\n",
       "<td>0.0196078</td>\n",
       "<td>0.9934641</td>\n",
       "<td>0.3921569</td>\n",
       "<td>1.8062983</td>\n",
       "<td>-60.7843137</td>\n",
       "<td>80.6298277</td></tr>\n",
       "<tr><td></td>\n",
       "<td>12</td>\n",
       "<td>0.1977616</td>\n",
       "<td>0.6</td>\n",
       "<td>0.0</td>\n",
       "<td>0.6666667</td>\n",
       "<td>0.0</td>\n",
       "<td>0.9934641</td>\n",
       "<td>0.0</td>\n",
       "<td>1.6557734</td>\n",
       "<td>-100.0</td>\n",
       "<td>65.5773420</td></tr>\n",
       "<tr><td></td>\n",
       "<td>13</td>\n",
       "<td>0.1586941</td>\n",
       "<td>0.65</td>\n",
       "<td>0.0526316</td>\n",
       "<td>0.6194332</td>\n",
       "<td>0.0065359</td>\n",
       "<td>1.0</td>\n",
       "<td>0.1307190</td>\n",
       "<td>1.5384615</td>\n",
       "<td>-86.9281046</td>\n",
       "<td>53.8461538</td></tr>\n",
       "<tr><td></td>\n",
       "<td>14</td>\n",
       "<td>0.1353591</td>\n",
       "<td>0.7</td>\n",
       "<td>0.0</td>\n",
       "<td>0.5751880</td>\n",
       "<td>0.0</td>\n",
       "<td>1.0</td>\n",
       "<td>0.0</td>\n",
       "<td>1.4285714</td>\n",
       "<td>-100.0</td>\n",
       "<td>42.8571429</td></tr>\n",
       "<tr><td></td>\n",
       "<td>15</td>\n",
       "<td>0.1094101</td>\n",
       "<td>0.75</td>\n",
       "<td>0.0</td>\n",
       "<td>0.5368421</td>\n",
       "<td>0.0</td>\n",
       "<td>1.0</td>\n",
       "<td>0.0</td>\n",
       "<td>1.3333333</td>\n",
       "<td>-100.0</td>\n",
       "<td>33.3333333</td></tr>\n",
       "<tr><td></td>\n",
       "<td>16</td>\n",
       "<td>0.0923828</td>\n",
       "<td>0.8</td>\n",
       "<td>0.0</td>\n",
       "<td>0.5032895</td>\n",
       "<td>0.0</td>\n",
       "<td>1.0</td>\n",
       "<td>0.0</td>\n",
       "<td>1.25</td>\n",
       "<td>-100.0</td>\n",
       "<td>25.0</td></tr>\n",
       "<tr><td></td>\n",
       "<td>17</td>\n",
       "<td>0.0665933</td>\n",
       "<td>0.85</td>\n",
       "<td>0.0</td>\n",
       "<td>0.4736842</td>\n",
       "<td>0.0</td>\n",
       "<td>1.0</td>\n",
       "<td>0.0</td>\n",
       "<td>1.1764706</td>\n",
       "<td>-100.0</td>\n",
       "<td>17.6470588</td></tr>\n",
       "<tr><td></td>\n",
       "<td>18</td>\n",
       "<td>0.0477968</td>\n",
       "<td>0.9</td>\n",
       "<td>0.0</td>\n",
       "<td>0.4473684</td>\n",
       "<td>0.0</td>\n",
       "<td>1.0</td>\n",
       "<td>0.0</td>\n",
       "<td>1.1111111</td>\n",
       "<td>-100.0</td>\n",
       "<td>11.1111111</td></tr>\n",
       "<tr><td></td>\n",
       "<td>19</td>\n",
       "<td>0.0276973</td>\n",
       "<td>0.95</td>\n",
       "<td>0.0</td>\n",
       "<td>0.4238227</td>\n",
       "<td>0.0</td>\n",
       "<td>1.0</td>\n",
       "<td>0.0</td>\n",
       "<td>1.0526316</td>\n",
       "<td>-100.0</td>\n",
       "<td>5.2631579</td></tr>\n",
       "<tr><td></td>\n",
       "<td>20</td>\n",
       "<td>0.0125566</td>\n",
       "<td>1.0</td>\n",
       "<td>0.0</td>\n",
       "<td>0.4026316</td>\n",
       "<td>0.0</td>\n",
       "<td>1.0</td>\n",
       "<td>0.0</td>\n",
       "<td>1.0</td>\n",
       "<td>-100.0</td>\n",
       "<td>0.0</td></tr></table></div>"
      ],
      "text/plain": [
       "    group    lower_threshold    cumulative_data_fraction    response_rate    cumulative_response_rate    capture_rate    cumulative_capture_rate    lift      cumulative_lift    gain      cumulative_gain\n",
       "--  -------  -----------------  --------------------------  ---------------  --------------------------  --------------  -------------------------  --------  -----------------  --------  -----------------\n",
       "    1        0.940575           0.05                        1                1                           0.124183        0.124183                   2.48366   2.48366            148.366   148.366\n",
       "    2        0.892198           0.1                         1                1                           0.124183        0.248366                   2.48366   2.48366            148.366   148.366\n",
       "    3        0.82637            0.15                        1                1                           0.124183        0.372549                   2.48366   2.48366            148.366   148.366\n",
       "    4        0.759546           0.2                         0.947368         0.986842                    0.117647        0.490196                   2.35294   2.45098            135.294   145.098\n",
       "    5        0.708193           0.25                        1                0.989474                    0.124183        0.614379                   2.48366   2.45752            148.366   145.752\n",
       "    6        0.636431           0.3                         0.894737         0.973684                    0.111111        0.72549                    2.22222   2.4183             122.222   141.83\n",
       "    7        0.547865           0.35                        0.684211         0.932331                    0.0849673       0.810458                   1.69935   2.31559            69.9346   131.559\n",
       "    8        0.449983           0.4                         0.789474         0.914474                    0.0980392       0.908497                   1.96078   2.27124            96.0784   127.124\n",
       "    9        0.392787           0.45                        0.210526         0.836257                    0.0261438       0.934641                   0.522876  2.07698            -47.7124  107.698\n",
       "    10       0.320766           0.5                         0.315789         0.784211                    0.0392157       0.973856                   0.784314  1.94771            -21.5686  94.7712\n",
       "    11       0.242574           0.55                        0.157895         0.727273                    0.0196078       0.993464                   0.392157  1.8063             -60.7843  80.6298\n",
       "    12       0.197762           0.6                         0                0.666667                    0               0.993464                   0         1.65577            -100      65.5773\n",
       "    13       0.158694           0.65                        0.0526316        0.619433                    0.00653595      1                          0.130719  1.53846            -86.9281  53.8462\n",
       "    14       0.135359           0.7                         0                0.575188                    0               1                          0         1.42857            -100      42.8571\n",
       "    15       0.10941            0.75                        0                0.536842                    0               1                          0         1.33333            -100      33.3333\n",
       "    16       0.0923828          0.8                         0                0.503289                    0               1                          0         1.25               -100      25\n",
       "    17       0.0665933          0.85                        0                0.473684                    0               1                          0         1.17647            -100      17.6471\n",
       "    18       0.0477968          0.9                         0                0.447368                    0               1                          0         1.11111            -100      11.1111\n",
       "    19       0.0276973          0.95                        0                0.423823                    0               1                          0         1.05263            -100      5.26316\n",
       "    20       0.0125566          1                           0                0.402632                    0               1                          0         1                  -100      0"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "my_gbm_metrics = my_gbm.model_performance(train)\n",
    "my_gbm_metrics.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
